new Vue({
  el: "#app",
  data() {
    return {
      loading: false,
      reptile_config: [
        {
          Reptile_SerialNumber: "",
          Reptile_Type: "",
          Reptile_URL: "",
          Reptile_Class: "",
          isLogin: "0",
          Login_URL: "",
          Children_SerialNumber: "",
          Reptile_Quantity: "",
          Setlnterval: "",
          News_Type: "0",
        },
      ],
      reptile_config_detail: [
        {
          Reptile_Detail_SerialNumber: "",
          Reptile_SerialNumber: "",
          type1: "",
          value1: "",
          class1: "",
          number: "",
        },
      ],
      reptile_config_detail_element: [
        {
          Reptile_Detail_SerialNumber: "",
          Reptile_SerialNumber: "",
          type2: "",
          value2: "",
          class2: "",
          img: "",
          imgValue: "",
          href: "",
          content: [
            {
              title: "",
              content: "",
            },
          ],
        },
      ],
      Reptile_Type: [
        { label: "产业技术", value: "0" },
        { label: "文化宣传", value: "1" },
        { label: "产品展示", value: "2" },
        { label: "政策", value: "3" },
        { label: "法规", value: "4" },
      ],
      props: {
        multiple: true,
        label: "New_Type_Name",
        value: "New_Type_SerialNumber",
      },
      options: [],
      type: [],
    };
  },
  mounted() {
    this.getData();
  },
  methods: {
    getData() {
      const that = this;
      $.ajax({
        url: `${BASE_URL1}/NewTypeAll`,
        type: "POST",
        data: {
          Data: JSON.stringify({
            Add: {
              news_info: [this.form],
              // news_info: [{News_Type: this.reptile_config[0].News_Type}],
            },
          }),
        },
        success: function (data) {
          that.options = data;
        },
        dataType: "json",
      });
    },
    submitForm(formName) {
      let _this = this;
      this.reptile_config[0].Detail_JSON = JSON.stringify(_this.type);
      this.reptile_config[0].NEW = [
        {
          LayoutNews: this.reptile_config_detail,
          NewList: this.reptile_config_detail_element,
        },
      ];
      console.log(this.reptile_config);
      if (this.reptile_config[0].URL !== undefined) {
        $.ajax({
          // url: DomainName + "/ReptileConfigAction?token=" + $.cookie("token"),
          url: "https://service.kdddy.cn/donghuiForRedis/insert",
          type: "POST",
          data: {
            Data: JSON.stringify(this.reptile_config),
          },
          // success: function (res) {

          success: (res) => {
            console.log(this.reptile_config[0].URL, "111");
            if (this.reptile_config[0].URL !== undefined) {
              _this.$message.success("提交成功");
              window.history.go(-1);
            } else {
              _this.$message.error("操作失败，请联系开发者");
            }
          },
          error: function () {
            _this.$message.error("操作失败，请稍后再试");
          },
          complete: function (XMLHttpRequest) {
            _this.loading = false;
            if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
              window.parent.document.location.href =
                absolutepath() +
                XMLHttpRequest.getResponseHeader("CONTENTPATH");
            }
          },
        });
      } else {
        _this.$message.error("请填写完整信息");
      }

      // return;

      this.$refs[formName].validate((valid) => {
        if (valid) {
          _this.loading = true;
          // this.reptile_config[this.reptile_config.length - 1]["Children"] = {
          //   reptile_config_detail: this.reptile_config_detail,
          // };
          console.log(this.reptile_config);
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    add_reptile_config() {
      this.reptile_config.push({
        Reptile_SerialNumber: "",
        Reptile_URL: "",
        Reptile_Class: "",
        isLogin: "",
        Login_URL: "",
        Children_SerialNumber: "",
        Reptile_Quantity: "",
        Setlnterval: "",
      });
      console.log(this.reptile_config);
    },
    delet_reptile_config() {
      if (this.reptile_config.length > 1) {
        this.reptile_config.pop();
      } else {
        this.$message({
          message: "不能在删除了",
          type: "warning",
        });
      }
    },
    add_reptile_config_detail() {
      this.reptile_config_detail.push({
        Reptile_Detail_SerialNumber: "",
        Reptile_SerialNumber: "",
        type1: "",
        value1: "",
        class1: "",
        number: "",
      });
    },
    delet_reptile_config_detail() {
      if (this.reptile_config_detail.length > 1) {
        this.reptile_config_detail.pop();
      } else {
        this.$message({
          message: "不能在删除了",
          type: "warning",
        });
      }
    },
    add_reptile_config_detail_element() {
      this.reptile_config_detail_element.push({
        Reptile_Detail_SerialNumber: "",
        Reptile_SerialNumber: "",
        type2: "",
        value2: "",
        class2: "",
        img: "",
        imgValue: "",
        href: "",
        content: [
          {
            title: "",
            content: "",
          },
        ],
      });
    },
    delet_reptile_config_detail_element() {
      if (this.reptile_config_detail_element.length > 1) {
        this.reptile_config_detail_element.pop();
      } else {
        this.$message({
          message: "不能在删除了",
          type: "warning",
        });
      }
    },
    add_reptile_config_detail_element_content(index) {
      this.reptile_config_detail_element[index].content.push({
        title: "",
        content: "",
      });
    },
    delet_reptile_config_detail_element_content(index) {
      if (this.reptile_config_detail_element[index].content.length > 1) {
        this.reptile_config_detail_element[index].content.pop();
      } else {
        this.$message({
          message: "不能在删除了",
          type: "warning",
        });
      }
    },
  },
});
